const hanshu = {
  textEach: (string, n) => {
    if(string.length>n){
      string = string.substring(0,n)+'...'
    }
    return string
  },
  regCheck: (string,reg) => {
    if(reg.test(string)){
      return true
    }
    return false
  },
  getDateDiff: (timestamp) =>{
    // 补全为13位
    let arrTimestamp = (timestamp + '').split('');
    for (let start = 0; start < 13; start++) {
      if (!arrTimestamp[start]) {
        arrTimestamp[start] = '0';
      }
    }
    timestamp = arrTimestamp.join('') * 1;
    let zero = function (value) {
      if (value < 10) {
        return '0' + value;
      }
      return value;
    };
      return (function () {
        let date = new Date(timestamp);
        return date.getFullYear() + '-' + zero(date.getMonth() + 1) + '-' + zero(date.getDate());
      })();
  }
}

export default hanshu
